﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLBH.ModelInterface;
using QLBH.DataModel;
using QLBH.Model.Controller;
using QLBH.ModelFactory;

namespace QLBH.CongNo
{
    public partial class SelectKhachHangDlg : Form
    {
        public SelectKhachHangDlg()
        {
            InitializeComponent();
        }

        private void SelectKhachHangDlg_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode==Keys.Escape)
            {
                btnCancel_Click(btnCancel, null);
            }
            else if (e.KeyCode==Keys.Enter)
            {
                btnSelect_Click(btnSelect, null);
            }
        }

        private void btnSelect_Click(object sender, EventArgs e)
        {

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void SelectKhachHangDlg_Load(object sender, EventArgs e)
        {
            // load ds khach hang
            List<IKhachHangModel> khachhangmodels = new List<IKhachHangModel>();

            List<KHACHHANG> khs = KhachHangController.GetInstance().GetAll().ToList();
            foreach (KHACHHANG kh in khs)
            {
                IKhachHangModel khmodel = SaleProductModelFactory.GetKhachHangModelInstance();
                khmodel.InitFromEntity(kh);
                khachhangmodels.Add(khmodel);
            }
            dataGridViewEx1.DataSource = khachhangmodels;
        }
    }
}
